<?php
/**
 * Created by PhpStorm.
 * User: lengbin
 * Date: 2018/6/21
 * Time: 下午2:32
 */

namespace common\core\actions;

use common\core\base\Action;

/**
 * edit
 *
 * Class EditAction
 * @package common\core\actions
 */
class EditAction extends Action
{
    /**
     * request param
     *
     * @var string
     */
    public $modelByParams = 'id';

    /**
     * delete filed name
     *
     * @var string
     */
    public $isDeleteName = 'is_delete';

    /**
     *  call_user_func
     * @var string
     */
    public $model;


    public function init()
    {
        $id = \Yii::$app->request->get($this->modelByParams);

        if ($this->model instanceof \Closure) {
            $this->model = call_user_func($this->model, $id);
        }

        if (empty($this->model)) {
            $this->model = $this->modelClass->getById($id, $this->isDeleteName);
        }
        parent::init();
    }

    public function run()
    {
        return $this->controller->render($this->view, $this->getData($this->model));
    }

}